package com.ruoyi.web.controller.server;

import java.util.List;
import javax.validation.Valid;

import com.ruoyi.server.domain.dto.ServerInfoAddDTO;
import com.ruoyi.server.domain.dto.ServerInfoPageDTO;
import com.ruoyi.server.domain.dto.ServerInfoUpdateDTO;
import com.ruoyi.server.service.IServerInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.server.domain.ServerInfo;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 服务器Controller
 *
 * @author ghostmen
 * @date 2024-10-31
 */
@Validated
@RestController
@RequestMapping("/server/info")
@Api(value = "服务器", tags = "服务器接口")
public class ServerInfoController extends BaseController {

    @Autowired
    private IServerInfoService serverInfoService;

    /**
     * 查询服务器列表
     */
    @PreAuthorize("@ss.hasPermi('server:info:list')")
    @GetMapping("/list")
    @ApiOperation(value = "查询服务器列表", notes = "传入serverInfo")
    public TableDataInfo list(ServerInfoPageDTO pageDTO) {
        List<ServerInfo> list = serverInfoService.selectServerInfoList(pageDTO);
        return getDataTable(list);
    }

    /**
     * 获取服务器详细信息
     */
    @PreAuthorize("@ss.hasPermi('server:info:query')")
    @GetMapping(value = "/{serverId}")
    @ApiOperation(value = "获取服务器详细信息", notes = "传入serverId")
    public AjaxResult getInfo(@PathVariable("serverId") Long serverId) {
        return success(serverInfoService.selectServerInfoByServerId(serverId));
    }

    /**
     * 新增服务器
     */
    @PreAuthorize("@ss.hasPermi('server:info:add')")
    @Log(title = "服务器", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation(value = "新增服务器", notes = "传入addDTO")
    public AjaxResult add(@Valid @RequestBody ServerInfoAddDTO addDTO) {
        addDTO.setLoginUser(getLoginUser());
        return toAjax(serverInfoService.insertServerInfo(addDTO));
    }

    /**
     * 修改服务器
     */
    @PreAuthorize("@ss.hasPermi('server:info:edit')")
    @Log(title = "服务器", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation(value = "修改服务器", notes = "传入updateDTO")
    public AjaxResult edit(@Valid @RequestBody ServerInfoUpdateDTO updateDTO) {
        updateDTO.setLoginUser(getLoginUser());
        return toAjax(serverInfoService.updateServerInfo(updateDTO));
    }

    /**
     * 删除服务器
     */
    @PreAuthorize("@ss.hasPermi('server:info:remove')")
    @Log(title = "服务器", businessType = BusinessType.DELETE)
    @DeleteMapping("/{serverIds}")
    @ApiOperation(value = "删除服务器", notes = "传入serverIds")
    public AjaxResult remove(@PathVariable Long[] serverIds) {
        return toAjax(serverInfoService.deleteServerInfoByServerIds(serverIds));
    }
}
